home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
tools
/
zmc3v078
/
zmc3v078.lzh
/
SRCSV078.LZH
/
ARCC.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-09
|
14KB
|
550 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "etc.h"
#include "makezmd3.h"
#include "parsesub.h"
#include "velo.h"
#include "68lib.h"
#include "structs.h"
#include "structs2.h"
UBYTE *makeARCCCommand(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf);
UBYTE *makeARCClevel(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
DWORD no, TRKINF *trkinf);
UBYTE *makeARCClevel0(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf, int no, int mode);
UBYTE *makeARCCdeepen(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no,
TRKINF *trkinf);
UBYTE *makeARCCcontrol(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCorigin(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCreset(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCswitch(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCwaveform(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCsync(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCmode(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCphase(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no);
UBYTE *makeARCCoffset(UBYTE *zms,TRKINF *trkinf, const BYTE target[],DWORD no);
extern DWORD line;
extern char *linebuf;
extern LINEDATA *ld;
UBYTE *makeARCCCommand(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf)
{
DWORD no, tmpDWORD;
int i, trk,err;
DWORD line_ = line;
char *linebuf_ = linebuf;
const char *comtbl[] = {
"level","depth","deepen","control","origin","reset",
"speed","delay","waveform","switch","sync","mode","phase",
"offset",
NULL
};
zms = getnum2(zms, &no, &err);
if (err) {
zmserror("[ARCC] command must contain the ARCC target number.",line_,linebuf_,zms,0,1);
} else if (no < 1 && 4< no) {
zmserror("ARCC target number is out of range.",line_,linebuf_,zms,0,1);
}
no--;
zms = skipSpc(zms);
if (*zms++ != '.') {
zmserror("[ARCC] format error.",line_,linebuf_,zms,0,1);
}
for (i = 0;;i++) {
if (!comtbl[i]) {
i = -1;
break;
} else if (!stricmp2(zms,comtbl[i])) {
zms += strlen(comtbl[i]);
break;
}
}
switch (i) {
case 0: /* [ARCCn.level */
case 1: /* [ARCCn.depth */
zms = makeARCClevel(zms,trkdata,target,no,trkinf);
break;
case 2: /* deepen */
zms = makeARCCdeepen(zms,trkdata,target,no,trkinf);
break;
case 3: /* control */
zms = makeARCCcontrol(zms,trkdata,target,no);
break;
case 4: /* origin */
zms = makeARCCorigin(zms,trkdata,target,no);
break;
case 5: /* reset */
zms = makeARCCreset(zms,trkdata,target,no);
break;
case 6: /* speed */
{
const BYTE parabytes[8] = {2,2,2,2,2,2,2,2};
zms = makeZmdManyParas2(zms,trkdata,target,line,linebuf,
0xE6, 8, parabytes, 1, no, 0, 2, 1,
"[ARCCn.speed]: too many parameters.",
"[ARCCn.speed] can't use relatinal parameters.",
"");
}
break;
case 7: /* delay */
{
const BYTE parabytes[9] = {2,2,2,2,2,2,2,2,2};
zms = makeZmdManyParas2(zms,trkdata,target,line,linebuf,
0xE7, 9, parabytes, 1, no, 0, 1, 0,
"[ARCCn.delay]: too many parameters.",
"[ARCCn.delay] can't use relatinal parameters.",
"");
}
break;
case 8: /* waveform */
zms = makeARCCwaveform(zms,trkdata,target,no);
break;
case 9: /* switch */
zms = makeARCCswitch(zms,trkdata,target,no);
break;
case 10: /* sync */
zms = makeARCCsync(zms,trkdata,target,no);
break;
case 11: /* mode */
zms = makeARCCmode(zms,trkdata,target,no);
break;
case 12: /* phase */
zms = makeARCCphase(zms,trkdata,target,no);
break;
case 13: /* offset */
zms = makeARCCoffset(zms,trkinf,target,no);
break;
default: /* ERROR */
break;
}
zms = skipSpc(zms);
if (*zms++ != ']') {
zmserror("[ARCC] is not closed.",line_,linebuf_,zms,0,1);
}
return zms;
}
UBYTE *makeARCClevel(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no,
TRKINF *trkinf)
{
const char *p[] = {"1/8", "off", "optional", "on", NULL};
DWORD mode;
int err;
UBYTE *zms_;
int i, flag = 1;
zms = zms_ = skipSpc(zms);
for (i = 0; i < 4; i++) {
if (!stricmp2(zms, p[i])) {
flag = 0;
break;
}
}
zms = getnum4(zms, &mode, &err, p,-1);
zms = skipSpc(zms);
if (flag && (*zms == ']' || *zms == ',')) { /* omit the mode */
mode = 2;
zms = zms_;
} else {
if (err < 0) {
mode = 0;
} else if (err) {
zmserror("[ARCCn.LEVEL] format error.",line,linebuf,zms,0,1);
}
}
zms = skipSpc(zms);
if (*zms == ',') {
zms++;
}
zms = makeARCClevel0(zms,trkdata,target,trkinf,no,mode);
return zms;
}
UBYTE *makeARCClevel0(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
TRKINF *trkinf, int no, int mode)
{
DWORD tmpDWORD;
int trk,err;
DWORD line_ = line;
UBYTE *zms_ = zms;
LINEDATA *ld_ = ld;
for (trk = 0; target[trk] >= 0; trk++) {
int i;
VELOETCVAR v[17];
const int Trk = target[trk];
line = line_;
ld = ld_;
zms = makeZmdEigDepthSub(zms_,v,&trkinf[Trk].arccpos,
&trkinf[Trk].arccnum,1);
*trkdata[Trk].zmd++ = 0xE5;
*trkdata[Trk].zmd++ = no * 2;
if (mode == -2 && trkinf[Trk].arccnum < 2) {
if (trkinf[Trk].arccnum == 0) { /* arcc sw off */
/*OK*/
*trkdata[Trk].zmd++ = 0x00;
*trkdata[Trk].zmd++ = 0x00;
} else if (trkinf[Trk].arccnum == 1) { /* arcc single */
/*OK*/
int v_ = v[0].var[0] + trkinf[Trk].arccofst[no];
if (v_ > 127) {
v_ = 127;
} else if (v_ < -128) {
v_ = -128;
}
*trkdata[Trk].zmd++ = 0x01;
*trkdata[Trk].zmd++ = 0x01;
*trkdata[Trk].zmd++ = v_;
}
} else { /* arcc dep1/8 */
/*OK*/ UBYTE *zmd__;
UBYTE flg = 0;
if (mode == -2) {
mode = 0xFF;
} else if (mode == 2 && trkinf[Trk].arccnum == 1) {
mode = 0x01;
}
*trkdata[Trk].zmd++ = mode;
zmd__ = trkdata[Trk].zmd++;
for (i = 0; i < trkinf[Trk].arccnum; i++) {
trkinf[Trk].arcc[i].var[0] = v[i].var[0];
trkinf[Trk].arcc[i].relflg[0] = v[i].relflg[0];
flg >>= 1;
if (v[i].relflg[0] != 2) {
int v_ = v[i].var[0] + trkinf[Trk].arccofst[no];
if (v_ > 127) {
v_ = 127;
} else if (v_ < -128) {
v_ = -128;
}
*trkdata[Trk].zmd++ = v_;
flg |= 0x80;
}
}
for (i = trkinf[Trk].arccnum; i < 8; i++) {
trkinf[Trk].arcc[i].var[0] = 0;
trkinf[Trk].arcc[i].relflg[0] = 2;
flg >>= 1;
flg &= 0x7F;
}
*zmd__ = flg;
}
}
return zms;
}
UBYTE *makeARCCdeepen(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no,
TRKINF *trkinf)
{
const char *p[] = {"off", "on", NULL};
DWORD mode;
int err, trk;
const BYTE parabytes[3] = { 3, 1, 3 };
zms = getnum4(zms, &mode, &err, p, 0);
if (err < 0) {
mode = 0;
} else if (err > 0) {
zmserror("[ARCCn.DEEPEN] format error.",line,linebuf,zms,0,1);
}
if (*zms == ',') {
zms++;
}
zms = makeZmdManyParas2A(zms,trkdata,target,line,linebuf,
0xDB, 3, parabytes, 1, no, mode,
"[ARCCn.DEEPEN]: too many parameters.",
"[ARCCn.DEEPEN] can't use relational parameters.",
"");
return zms;
}
UBYTE *makeARCCcontrol(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
DWORD para;
int err, trk;
const char *p[] = {
"bank_msb", "vibrato", "ctrl2", "ctrl3", "ctrl4", "portament_time",
"data_entry_msb", "volume", "ctrl8", "ctrl9", "panpot", "expression",
"ctrl12", "ctrl13", "ctrl14", "ctrl15", "ctrl16", "ctrl17", "ctrl18",
"ctrl19", "ctrl20", "ctrl21", "ctrl22", "ctrl23", "ctrl24", "ctrl25",
"ctrl26", "ctrl27", "ctrl28", "ctrl29", "ctrl30", "ctrl31",
"bank_lsb", "ctrl33", "ctrl34", "ctrl35", "ctrl36", "data_entry_lsb",
"ctrl38", "ctrl39", "ctrl40", "ctrl41", "ctrl42",
"ctrl43", "ctrl44", "ctrl45", "ctrl46", "ctrl47", "ctrl48", "ctrl49",
"ctrl50", "ctrl51", "ctrl52", "ctrl53", "ctrl54", "ctrl55", "ctrl56",
"ctrl57", "ctrl58", "ctrl59", "ctrl60", "ctrl61", "ctrl62", "ctrl63",
"damper", "portament", "sostenuto", "soft", "ctrl68", "freeze",
"ctrl70", "ctrl71", "ctrl72", "ctrl73", "ctrl74", "ctrl75", "ctrl76",
"ctrl77", "ctrl78", "ctrl79", "ctrl80", "ctrl81", "ctrl82", "ctrl83",
"portament_ctrl", "ctrl85", "ctrl86", "ctrl87", "ctrl88", "ctrl89",
"ctrl90", "reverb", "tremolo", "chorus", "delay", "phaser", "data_increment",
"data_decrement", "nrpn_lsb", "nrpn_msb", "rpn_lsb", "rpn_msb",
"ctrl102", "ctrl103", "ctrl104", "ctrl105", "ctrl106", "ctrl107",
"ctrl108", "ctrl109", "ctrl110", "ctrl111", "ctrl112", "ctrl113",
"ctrl114", "ctrl115", "ctrl116", "ctrl117", "ctrl118", "ctrl119",
"all_sound_off", "reset_all_controllers", "local", "all_notes_off",
"omni_off", "omni_on", "mono", "poly", NULL
};
zms = getnum4(zms, ¶, &err, p, 0);
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xF7;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = 0x80;
*trkdata[Trk].zmd++ = para;
}
return zms;
}
UBYTE *makeARCCorigin(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
DWORD para;
int trk;
zms = get1AbsPara(zms,¶,0,127,
"[ARCCn.ORIGIN]: parameter is out of range.",
"[ARCCn.ORIGIN]: parameter can't omit.");
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xF7;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = 0x20;
*trkdata[Trk].zmd++ = para;
}
return zms;
}
UBYTE *makeARCCreset(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
DWORD para;
int trk;
zms = get1AbsPara(zms,¶,0,127,
"[ARCCn.RESET]: parameter is out of range.",
"[ARCCn.RESET]: parameter can't omit.");
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xF7;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = 0x40;
*trkdata[Trk].zmd++ = para;
}
return zms;
}
UBYTE *makeARCCwaveform(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
const char *p[] = {"saw", "square", "triangle", "s.saw", "random", NULL};
DWORD form;
int err, trk;
zms = getnum4(zms, &form, &err, p, 0);
if (!err < 0) {
zmserror("[ARCCn.WAVEFORM] format error.",line,linebuf,zms,0,1);
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xC9;
*trkdata[Trk].zmd++ = no * 2;
if (form >= 8) {
form += 0x8000 - 8;
}
putWord(trkdata[Trk].zmd, form);
trkdata[Trk].zmd += 2;
}
return zms;
}
UBYTE *makeARCCswitch(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
const char *p[] = {"1/8", "off", "optional", "on", NULL};
DWORD mode;
int err, trk;
zms = getnum4(zms, &mode, &err, p, -1);
if (!err < 0) {
zmserror("[ARCCn.SWITCH] format error.",line,linebuf,zms,0,1);
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xB3;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = mode;
}
return zms;
}
UBYTE *makeARCCsync(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
const char *p[] = {"off", "on", NULL};
DWORD mode, c = 0;
UBYTE mode2 = 0;
int i, err, trk;
zms = getnum4(zms, &mode, &err, p, 0);
if (!err < 0) {
zmserror("[ARCCn.SYNC] format error.",line,linebuf,zms,0,1);
}
zms = skipSpc(zms);
if (*zms == ',') {
zms = getnum2(++zms, &c, &err);
if (err < 0) {
c = 0;
} else if (c > 0) {
zmserror("[ARCCn.SYNC] format error.",line,linebuf,zms,0,1);
}
}
for (i = 0; i < 4; i++) {
mode2 <<= 1;
if (mode & 1) {
mode2++;
}
mode >>= 1;
}
for (i = 0; i < 4; i++) {
mode2 <<= 1;
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xB5;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = mode2;
putWord(trkdata[Trk].zmd, c);
trkdata[Trk].zmd += 2;
}
return zms;
}
UBYTE *makeARCCmode(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
const char *p[] = {"normal", "special", "enhanced", NULL};
DWORD mode;
int err, trk;
zms = getnum4(zms, &mode, &err, p, 0);
if (!err < 0) {
zmserror("[ARCCn.MODE] format error.",line,linebuf,zms,0,1);
}
if (mode == 2) {
mode = 1;
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xB4;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = mode - 1;
}
return zms;
}
UBYTE *makeARCCphase(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],DWORD no)
{
const char *p[] = {"normal", "reverse", "inverse", NULL};
DWORD mode;
int err, trk;
zms = getnum4(zms, &mode, &err, p, 0);
if (!err < 0) {
zmserror("[ARCCn.PHASE] format error.",line,linebuf,zms,0,1);
}
if (mode == 2) {
mode = 1;
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
*trkdata[Trk].zmd++ = 0xF7;
*trkdata[Trk].zmd++ = no * 2;
*trkdata[Trk].zmd++ = 0x10;
*trkdata[Trk].zmd++ = -mode;
}
return zms;
}
UBYTE *makeARCCoffset(UBYTE *zms,TRKINF *trkinf, const BYTE target[],DWORD no)
{
/* const char *p[] = {"on", "off", NULL};*/
DWORD mode, offset;
int err, trk;
/* zms = getnum4(zms, &mode, &err, p, 0);*/
zms = getnum2(zms, &offset, &err);
if (!err < 0) {
zmserror("[ARCCn.OFFSET] format error.",line,linebuf,zms,0,1);
}
for (trk = 0; target[trk] >= 0; trk++) {
const int Trk = target[trk];
trkinf[Trk].arccofst[no] = offset;
}
return zms;
}